package com.BlogPark.service.RegistrationService.Impl;

import com.BlogPark.mapper.UserMapper;
import com.BlogPark.pojo.User;
import com.BlogPark.service.RegistrationService.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.BlogPark.common.utis.MD5Utils;
import java.util.List;



@Service
public class RegistrationServiceImpl implements RegistrationService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public User findUserByEmail(String email) {
        User user = userMapper.selectUserByEmail(email);
        return user;
    }

    /**
     * 用户注册
     * 这部分好像也用不到了
     * @param user
     * @return
     */
    @Override
    public String Register(User user) {
        String msg=null;
        List<User> userList = userMapper.checkout(user);
        if (userList.size()!=0) {
            System.out.println(userList.size());
            User checkUser = userList.set(0, user);
            //用户名、邮箱查重
            if (checkUser.getUsername().equals(user.getUsername())){
                msg="用户名已存在";
            }
        }else {
            String pwd = user.getPassword();
            user.setPassword(MD5Utils.getMd5(pwd));
            userMapper.AddUserOrUpdatePWD(user);
            msg="注册成功";
        }
        return msg;
    }

}
